using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_JXC_AccountSubjectDetail : Member, IRequiresSessionState
{
	protected ScriptManager sm;
	protected Literal ltrTitle;
	protected TextBox txtSearchBeginDate;
	protected TextBox txtSearchEndDate;
	protected DropDownList ddlSubject;
	protected Button btnSearch;
	protected UpdatePanel UpdatePanel1;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	protected UpdatePanel upList;
	private string linkHead = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerFinancemanage(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.txtSearchBeginDate.Text = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-01";
			this.txtSearchEndDate.Text = DateTime.Now.ToShortDateString();
			this.ddlSubjcetList();
			this.BindData();
		}
	}
	private void ddlSubjcetList()
	{
		this.ddlSubject.Items.Clear();
		string strWhere = "AccountSParentID=0 order by AccountSRootID,AccountSParentID desc";
		DataTable dataTable = BLLInstance.BllAccountSubject.GetList(strWhere).Tables[0];
		foreach (DataRow dataRow in dataTable.Rows)
		{
			int parentID = dataRow["AccountSubjectID"].ToInt32(new int[0]);
			BLLInstance.BllAccountSubject.BindSubjcet(this.ddlSubject, parentID, 1, "");
		}
		this.ddlSubject.Items.Insert(0, new ListItem("全部", "0"));
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.txtSearchBeginDate.Text = text2;
		}
		else
		{
			text2 = this.txtSearchBeginDate.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and DATEDIFF(DD, InputDate,'" + text2 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text2;
		}
		string text3 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text3))
		{
			this.txtSearchEndDate.Text = text3;
		}
		else
		{
			text3 = this.txtSearchEndDate.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			if (!string.IsNullOrEmpty(text2))
			{
				if (Convert.ToDateTime(text2) > Convert.ToDateTime(text3))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, InputDate,'" + text3 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text3;
		}
		string text4 = Fetch.Get("subjcetID");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddlSubject.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddlSubject.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text4) && text4 != "0")
		{
			text = text + " and AAItemAccountSID=" + text4;
			this.linkHead = this.linkHead + "&subjcetID=" + text4;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by AccountAoucherID asc";
		string value = this.txtSearchBeginDate.Text.Trim();
		string value2 = this.txtSearchEndDate.Text.Trim();
		if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2))
		{
			result = "order by InputDate asc";
		}
		return result;
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLJXC_View_AccountAoucherItemSubjcet where OwnerID=" + base.user.UserID + " ";
		int num2 = 10;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * num2 + 1;
		int endIndex = num * num2;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.rptList.DataSource = listPage;
		this.rptList.DataBind();
		decimal d = 0m;
		decimal num3 = 0m;
		decimal d2 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblBorrowPrice");
			Label label3 = (Label)this.rptList.Items[i].FindControl("lblLoanPrice");
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfBorrowPrice");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfLoanPrice");
			Label label4 = (Label)this.rptList.Items[i].FindControl("lblLend");
			Label label5 = (Label)this.rptList.Items[i].FindControl("lblMoney");
			int num4 = i + 1;
			if (num > 0)
			{
				num4 = (num - 1) * num2 + num4;
			}
			label.Text = num4.ToString();
			if (label5 != null)
			{
				decimal num5 = 0m;
				if (!string.IsNullOrEmpty(hiddenField.Value))
				{
					num5 = Convert.ToDecimal(hiddenField.Value);
				}
				decimal num6 = 0m;
				if (!string.IsNullOrEmpty(hiddenField2.Value))
				{
					num6 = Convert.ToDecimal(hiddenField2.Value);
				}
				decimal d3 = 0m;
				if (num5 > 0m && num6 == 0m)
				{
					label2.Text = num5.ToString();
					label3.Text = "";
					label4.Text = "借";
					label5.Text = num5.ToString();
					d3 = num5;
				}
				else
				{
					if (num5 == 0m && num6 > 0m)
					{
						label2.Text = "";
						label3.Text = num6.ToString();
						label4.Text = "贷";
						label5.Text = num6.ToString();
						d3 = num6;
					}
				}
				d += num5;
				num3 += num6;
				d2 += d3;
			}
		}
		Label label6 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalBorrowPrice");
		Label label7 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalLoanPrice");
		Label label8 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalLend");
		Label label9 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalMoney");
		decimal num7 = d - num3;
		if (num7 > 0m)
		{
			label8.Text = "借";
		}
		else
		{
			label8.Text = "贷";
		}
		label6.Text = d.ToString();
		label7.Text = num3.ToString();
		label9.Text = Math.Abs(num7).ToString();
		if (this.rptList.Items.Count == 0)
		{
			label8.Text = "";
		}
		string url = "AccountSubjectDetail.aspx?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, num2, listCount, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url, true);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
	protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BindData();
	}
}
